/*
 * @Author: yangrongxin
 * @Date: 2021-07-14 10:57:53
 * @LastEditors: guoju
 * @LastEditTime: 2021-12-29 17:06:47
 */
import { resolve } from 'path';

const {
  NODE_ENV,
  BUILD_ENV
} = process.env;

const config = {
  projectName: 'wxminiprogram',
  date: '2021-7-14',
  designWidth: 750,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2
  },
  sourceRoot: 'src',
  outputRoot: 'dist',
  plugins: [],
  defineConstants: {
    VERSION: "'2.0.0'", // 对应当前版本号
    API_APPCODE: "'HXTAPP'", // APPCODE
    API_CHANNELCODE: "'HXT_WXAPP'", // 渠道CODE
    SHOW_TEST_TOOLS: JSON.stringify(BUILD_ENV !== 'production' ? 'true' : 'false'), // 控制当前是不是展示测试工具->首页自动切换版本号
  },
  copy: {
    patterns: [
    ],
    options: {
    }
  },
  framework: 'react',
  alias: {
    '@/assets': resolve(__dirname, '..', 'src/assets'),
    '@/components': resolve(__dirname, '..', 'src/components'),
    '@/const': resolve(__dirname, '..', 'src/const'),
    '@/hooks': resolve(__dirname, '..', 'src/hooks'),
    '@/models': resolve(__dirname, '..', 'src/models'),
    '@/pages': resolve(__dirname, '..', 'src/pages'),
    '@/services': resolve(__dirname, '..', 'src/services'),
    '@/utils': resolve(__dirname, '..', 'src/utils'),
    '@/styles': resolve(__dirname, '..', 'src/styles'),
    '@/restful': resolve(__dirname, '..', 'src/restful'),
    '@/types': resolve(__dirname, '..', 'src/types'),
  },
  mini: {
    enableExtract: true,
    miniCssExtractPluginOption: {
      // 已使用cssModule来避免全局污染 可以取消css排序的检测
      ignoreOrder: true,
    },
    postcss: {
      pxtransform: {
        enable: true,
        config: {

        }
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    postcss: {
      autoprefixer: {
        enable: true,
        config: {
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  },
  onePxTransform: false, // 当前是否转换1px
}

module.exports = function (merge) {
  if ( BUILD_ENV === 'dev' ) {
    return merge({}, config, require('./dev'))
  }
  if ( BUILD_ENV === 'test' ) {
    return merge({}, config, require('./test'))
  }
  if ( BUILD_ENV === 'staging' ) {
    return merge({}, config, require('./staging'))
  }
  return merge({}, config, require('./prod'))
}
